#include	<stdio.h>
#include	<stdlib.h>
#include	<math.h>
#include	<string.h>
#include	"Uigp/igp.h"
#include	"ImageType/ImageType.h"
#include	"ImageType/ImageTool.h"
#include	"Ucamera/Pt2dType.h"
#include	"InterpolaionLib/Interpolation.h"
#include	"InterpolaionLib/Vornoi/VrLine.h"
#include    "InterpolaionLib/Vornoi/VrCell.h"


static void		read_command_line(int argc, char *argv[],
				  int *width, int *height,
				  char *imageFile, char *outFile );


int
main( int argc, char **argv )
{
	char	inFile[256],	outFile[256],	file[256];
	int	width,	height;
	pt2dA_type	*apt;

	read_command_line( argc, argv, &width, &height, inFile, outFile );

	if( pt2dA_read_from_file( &apt, inFile)< 0 )
		gpError( "interpolationCA", "Reading  %s  failed" );

	vrLine_type	vl0;
	vrLine_type vl1;

	vrLine_compute( &vl0, &apt->p[0].p, &apt->p[1].p );
	vrLine_compute( &vl1, &apt->p[0].p, &apt->p[2].p );

	vec2f_type	p;
	vrLine_SharePoint( &vl0, &vl1, &p );

	float	t0,	t1;
	t0 = vrLine_Point_distnace( &vl0, &p );
	t1 = vrLine_Point_distnace( &vl1, &p );

	fprintf( stdout, "%.2f  %.2f\n", t0, t1 );

	return( 1 );
}


static char *Usage = 
"Usage: ImagePyramid    [-W#]  [-H#]      imageFile  outFile";

static void	
read_command_line(int argc, char *argv[],
				  int *width, int *height,
				  char *inFile, char *outFile )
{
	int     k;

	k = 1;

	*width = 512;
	if (k < argc && gp_strnicmp(argv[k], "-W", 2) == 0  ){
		sscanf( argv[k]+2, "%d", width );
		k++;
	}

	*height = *width;
	if (k < argc && gp_strnicmp(argv[k], "-H", 2) == 0  ){
		sscanf( argv[k]+2, "%d", height );
		k++;
	}

	if (k < argc) {
		sprintf( inFile, "%s", argv[k]);
		k++;
	}
	else	error("read_command_line", Usage);
	
	if (k < argc) {
		sprintf( outFile, "%s", argv[k]);
		k++;
	}
	else	error("read_command_line", Usage);

}
